<?php
/**
 * @author ykm 2016/12/15
 * @describe 订单处理
 */

class erpapi_shop_matrix_pinduoduo_response_order extends erpapi_shop_response_order
{
    protected $_update_accept_dead_order = true;


    protected function _analysis()
    {
        parent::_analysis();
        
        if($this->_ordersdf['consignee']['area_city'] == '县') {
            $this->_ordersdf['consignee']['area_city'] = $this->_ordersdf['consignee']['area_state'];
        }

        // 拼多多平台优惠不算入结算

        if($this->_ordersdf['platform_discount']){
            $total_amount = $this->_ordersdf['total_amount'] - $this->_ordersdf['platform_discount'];
            $pmt_order    = $this->_ordersdf['pmt_order'] + $this->_ordersdf['platform_discount'];
            $payed        = $this->_ordersdf['payed'] - $this->_ordersdf['platform_discount'];

            if(round($total_amount,2) == round(($this->_ordersdf['cost_item'] + $this->_ordersdf['cost_freight'] + $this->_ordersdf['cost_protect'] + $this->_ordersdf['cost_tax'] + $this->_ordersdf['discount'] - $pmt_order - $this->_ordersdf['pmt_goods']),2)){

                $this->_ordersdf['total_amount']         = $total_amount;//订单总额
                $this->_ordersdf['pmt_order']            = $pmt_order;//订单优惠
                $this->_ordersdf['payed']                = $payed;//已支付
                $this->_ordersdf['payments'][0]['money'] = $payed;//收款单
            }
        }
    }



    protected function get_update_components()
    {
        $components = array('markmemo','marktype','custommemo');
        if (($this->_ordersdf['pay_status'] != $this->_tgOrder['pay_status']) ||($this->_ordersdf['shipping']['is_cod']=='true' && $this->_ordersdf['status'] == 'dead')) {
            $refundApply = app::get('ome')->model('refund_apply')->getList('apply_id',array('order_id'=>$this->_tgOrder['order_id'],'status|noequal'=>'3'));
            // 如果没有退款申请单，以前端为主
            if (!$refundApply) {
                $components[] = 'master';
            }
        }

        if ($this->_tgOrder['consignee']['name']=='' && $this->_tgOrder['consignee']['addr']=='' && $this->_ordersdf['consignee']['name']!='' && $this->_ordersdf['consignee']['addr']!=''){
            $components[] = 'consignee';
        }
        return $components;
    }
}
